package com.four.service.impl;

import com.four.entity.User;
import com.four.mapper.UserMapper;
import com.four.service.UserService;
import com.four.util.WebUtil;
import com.four.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ClassName:UserServiceImpl
 * Description:
 * date:2022/10/13 11:41
 *
 * @since JDK 1.8
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public Result findByNameAndPass(Integer phoneNumber, String password) {
        User user = userMapper.selectByNumberAndPass(phoneNumber, password);
        if (user != null){
            WebUtil.getSession().setAttribute("user",user);
            return new Result(200,"登录成功");
        }
        return new Result(500,"登陆失败");
    }

    @Override
    public Result insert(User user) {
        userMapper.insert(user);
        return new Result(200,"注册成功");
    }
}
